package uniandes.asoft.experimento1.cliente.principal;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.UnknownHostException;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import uniandes.asoft.experimento1.cliente.negocio.Vehiculo;

public class VehiculoPrincipal extends JFrame {

	public JTextField campoIntroducir;
	public JTextArea areaPantalla;
	public String servidorChat;
	private static Vehiculo vehiculo;

	private static final long serialVersionUID = 1L;

	public VehiculoPrincipal() {

		servidorChat = "localhost";

		Container contenedor = getContentPane();

		campoIntroducir = new JTextField();
		campoIntroducir.setEditable(false);
		campoIntroducir.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent evento) {
				vehiculo.enviarDatos(evento.getActionCommand());
				campoIntroducir.setText("");

			}
		});

		contenedor.add(campoIntroducir, BorderLayout.NORTH);
		areaPantalla = new JTextArea();
		contenedor.add(new JScrollPane(areaPantalla), BorderLayout.CENTER);
		setSize(300, 150);
		setVisible(true);

	}

	public static void main(String[] args) {

		VehiculoPrincipal vehiculoPrincipal = new VehiculoPrincipal();
		vehiculoPrincipal.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		try {

			for (int i = 0; i < 10; i++) {

				vehiculo = new Vehiculo(vehiculoPrincipal, "localhost", 12345);
				vehiculo.start();
			}

		} catch (UnknownHostException e) {

			e.printStackTrace();
		} catch (IOException e) {

			e.printStackTrace();
		}

	}

}
